<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./data.js"></script>
    <script src="./jquery.js"></script>
</head>
<body>
    <div class="shopcar">
    </div>
   <script>
        var car =document.querySelector('.shopcar')
        cartGoods.forEach(elem => {
            car.innerHTML+=`
            <input type="checkbox" ${elem.isChecked?"checked":""}> 
            <span>${elem.goodsname}</span>
            <span>${elem.price}</span>
            <br>
            `
        });

// 添加点击事件
        var check =document.querySelectorAll('input')
        var checked=$(':checked')
        if(check.length==checked.length){console.log('全选了');}
        else{console.log('未全选')}
        for (let i = 0; i < check.length; i++) {
            check[i].onclick=function(){
                var len=$("input:checked").length
                if (len==check.length) {
                    console.log('全选了');
                }else{
                    console.log('未全选');
                }
            }
        }
   </script> 
</body>
</html>